<template>
  <el-container>
    <el-header>
      <div class="logo">
        <img src="../assets/logo1.png" alt="">
        <span>非吃不可后台管理</span>
      </div>
        <el-dropdown>
            <span class="el-dropdown-link">
                <el-avatar shape="square" size="medium" :src="squareUrl"></el-avatar>
                <!-- <i class="el-icon-arrow-down el-icon--right"></i> -->
            </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>注销</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
    </el-header>
  <el-container>
    <el-aside :width="isCollapse ? '65px' : '200px'">
      <div class="toggle_btn">
        <i :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'" @click="toggleHandle"></i>
      </div>
        <el-menu
      :default-active="path"
      background-color="#333744"
      text-color="#fff"
      active-text-color="#ffd04b"
      unique-opened
      router
      @select="handleSelect"
      :collapse="isCollapse"
      :collapse-transition="false"
      >
      <el-submenu :index="'/' + item.path" :key="item.id" v-for="item in menuList">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span>{{item.authName}}</span>
        </template>
        <el-menu-item :index="'/' + itemChild.path" :key="itemChild.id" v-for="itemChild in item.children">
         <template>
           <i class="el-icon-location"></i>
           <span>{{itemChild.authName}}</span>
         </template>
       </el-menu-item>
      </el-submenu>
    </el-menu>
    </el-aside>
    <el-container>
      <el-main>
        <router-view></router-view>
      </el-main>
      <el-footer>Footer</el-footer>
    </el-container>
  </el-container>
  </el-container>
</template>
<script>
export default {
  data () {
    return {
      path: this.$router.currentRoute.path,
      isCollapse: false,
      menuList: [],
      squareUrl: 'https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png'
    }
  },
  created () {
    this.getMenuList()
  },
  methods: {
    async getMenuList () {
      try {
        var { data: res } = await this.$http.get('/menus')
        if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
        this.menuList = res.data
      } catch (err) {

      }
    },
    handleSelect (index) {
      console.log(index)
    },
    toggleHandle () {
      this.isCollapse = !this.isCollapse
    }
  }
}
</script>
<style lang="less" scoped>
.el-container {
    height: 100%;
}
.el-header {
    padding: 0;
    background-color: rgb(84,92,100);
    .logo {
      height: 100%;
      display: flex;
      align-items: center;
      img {
        height: 100%;
        margin-left: 10px;
      }
      span {
        color: #fff;
        font-size: 30px;
        margin-left: 10px;
        font-weight: bolder;
      }
    }
    .el-dropdown {
        position: absolute;
        right: 20px;
        top: 10px;
    }
}
.el-aside {
  background-color: #333744;
    .el-menu {
      border-right: none !important;
  }
}
.el-main {
  background-color: #eaedf1;
}
.toggle_btn {
  height: 30px;
  position: relative;
  font-size: 30px;
  color: yellowgreen;
  i {
    position: absolute;
    right: 2px;
    cursor: pointer;
  }
}
</style>
